import 'dart:convert';

class UpdatePostEntity {
  int? code = 0;
  String? message = '';
  bool? data = false; // 返回 true 表示更新成功
  int? timestamp = 0;

  UpdatePostEntity();

  factory UpdatePostEntity.fromJson(Map<String, dynamic> json) {
    return UpdatePostEntity()
      ..code = json['code']
      ..message = json['message']
      ..data = json['data']
      ..timestamp = json['timestamp'];
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'message': message,
      'data': data,
      'timestamp': timestamp,
    };
  }

  @override
  String toString() {
    return jsonEncode(this);
  }
}

class UpdatePostRequest {
  String id;
  String title;
  String content;
  int state; // 1: 发布, 0: 草稿

  UpdatePostRequest({
    required this.id,
    required this.title,
    required this.content,
    this.state = 1,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'content': content,
      'state': state,
    };
  }
}
